{% extends 'common/basic_form.html' %}
{% block titleblock %}
    机架
{% endblock %}
{% block script_content %}

    <script>
        {% ifequal is_add True%}
            $('#id_cabinet').empty();
            $("#id_cabinet").append("<option selected='selected' value=''>请选择机房</option>");
        {% endifequal %}
        {% ifequal is_add False%}
            $('#id_cabinet').empty();
            {% for cabinet in cabinet_list %}
                {% ifequal cabinet entity.cabinet.id %}
                    $("#id_cabinet").append("<option selected='selected' value='{{ cabinet.id }}'>{{ cabinet.name }}</option>");
                {% endifequal %}
                {% ifnotequal  cabinet entity.cabinet.id  %}
                    $("#id_cabinet").append("<option value='{{ cabinet.id }}'>{{ cabinet.name }}</option>");
                {% endifnotequal %}

            {% endfor %}
        {% endifequal %}
        $('#id_idc').change(function () {
            if ($('#id_idc').val() != '') {
                $.get('/frontend/cmdb/rack_list/load_cabinet_list/?idc_id=' + $('#id_idc').val(), function (rs) {
                    optionList = eval(rs)
                    $('#id_cabinet').empty()
                    for (var i = 0; i < optionList.length; i++) {
                        $("#id_cabinet").append("<option value=" + optionList[i].pk + ">" + optionList[i].fields.name + "</option>");
                    }
                })
            } else {
                $('#id_cabinet').empty()
                $("#id_cabinet").append("<option value=''>请选择机房</option>");
            }
        })
    </script>
{% endblock %}